<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
//引入DB
use DB;
use Auth;

class IndexController extends Controller
{
    //首页方法
    public function index(){
    	return view('home.index.index');
    }

    public function login(Request $request){
        if ($request -> method() === 'POST'){
            //        $this -> validate($request,[
//            //验证字段 => 规则1|规则2|规则3:参数|规则4...
//            //用户名，必填，最少2位，最长20位
//            'username'	=>	'required|min:2|max:20',
//            //密码，必填，最少6位，最长30位
//            'password'	=>	'required|min:6|max:30',
//            //验证码，必填，固定5位，必须合法验证码
//            'captcha'	=>	'required|size:5|captcha'
//        ]);
            $data = $request -> only('username','password');
            $data['status'] = '2';
            //开始用户信息的认证
            $result = Auth :: guard('member') -> attempt($data,$request -> get('remember_me'));
            if($result){
                //合法用户，跳转到后台首页

                return redirect() -> intended();

               
/*                return redirect() -> intended();
                
                
>>>>>>> sunyu*/
            }else{
                //非法用户，跳转登录页面
                return redirect('/login') -> withErrors([
                    'loginError' =>	'用户名或密码错误！'
                ]);
            }
        }else{
            return view('home.index.login');
        }

    }

}
